package scoping.blocks;

import ic.ast.decl.Type;

import java.util.HashMap;
import java.util.Map;

public abstract class ScopeBlock {
	protected HashMap<String, Type> _variables;
	protected HashMap<String, Integer> _registers;
	
	public ScopeBlock()	{
		_variables = new HashMap<>();
		_registers = new HashMap<>();
	}
	
	public Type getVariable(String key){
		if (_variables.containsKey(key)){
			return _variables.get(key);
		} else {
			return null;
		}
	}
	
	public void AddVariable(String varName, Type value){
		_variables.put(varName, value);
	}
	
	public void AddVariable(String varName, int registerValue){
		_registers.put(varName, registerValue);
	}
	
	public boolean TestAndSet (Map<String, Type> map , String name , Type type )
	{
		if (map.containsKey(name))
			return false;
		map.put(name, type);
		return true;
	}
	
	public int getVariableRegister(String varName){
		if (_registers.containsKey(varName)){
			return _registers.get(varName);
		} else {
			return -1;
		}
	}
}
